-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Point at inner item when it uses generic type param from outer item or Self
#148370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
```
error[E0401]: can't use generic parameters from outer item
--> $DIR/enum-definition-with-outer-generic-parameter-5997.rs:3:16
|
LL | fn f<Z>() -> bool {
| - type parameter from outer item
LL | enum E { V(Z) }
| ^ use of generic parameter from outer item
|
help: try introducing a local generic parameter here
|
LL | enum E<Z> { V(Z) }
| +++
```
```
error[E0401]: can't use generic parameters from outer item
--> $DIR/E0401.rs:4:39
|
LL | fn foo<T>(x: T) {
| - type parameter from outer item
LL | fn bfnr<U, V: Baz<U>, W: Fn()>(y: T) {
| ---- ^ use of generic parameter from outer item
| |
| generic parameter used in this inner function
|
help: try introducing a local generic parameter here
|
LL | fn bfnr<T, U, V: Baz<U>, W: Fn()>(y: T) {
| ++
```
```
error[E0401]: can't reference `Self` constructor from outer item
--> $DIR/do-not-ice-on-note_and_explain.rs:6:13
|
LL | impl<B> A<B> {
| ------------ the inner item doesn't inherit generics from this impl, so `Self` is invalid to reference
LL | fn d() {
LL | fn d() {
| - `Self` used in this inner item
LL | Self(1)
| ^^^^ help: replace `Self` with the actual type: `A`
```
|
rustbot has assigned @JonathanBrouwer. Use |
Self
| help: try introducing a local generic parameter here | ||
| | | ||
| LL | reuse Trait::static_methodT, { | ||
| | ++ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pre-existing mistake with delegation suggestion, we just make it obvious now. This needs to be fixed separately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there already an issue for this? If not lets make one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed it in last commit
```
error[E0401]: can't use generic parameters from outer item
--> $DIR/const-param-from-outer-fn.rs:3:9
|
LL | fn foo<const X: u32>() {
| - const parameter from outer item
LL | fn bar() -> u32 {
| --- generic parameter used in this inner function
LL | X
| ^ use of generic parameter from outer item
|
help: try introducing a local generic parameter here
|
LL | fn bar<X>() -> u32 {
| +++
```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few nits, other than that it looks good
This comment has been minimized.
This comment has been minimized.
|
r=me when ci is green |
|
@bors r=JonathanBrouwer |
Rollup of 5 pull requests Successful merges: - #144194 (Provide additional context to errors involving const traits) - #148232 (ci: add runners for vanilla LLVM 21) - #148240 (rustc_codegen: fix musttail returns for cast/indirect ABIs) - #148247 (Remove a special case and move another one out of reachable_non_generics) - #148370 (Point at inner item when it uses generic type param from outer item or `Self`) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #148370 - estebank:outer-param, r=JonathanBrouwer Point at inner item when it uses generic type param from outer item or `Self` Partially address #37892. In E0401 generated in resolve: ``` error[E0401]: can't use generic parameters from outer item --> $DIR/E0401.rs:4:39 | LL | fn foo<T>(x: T) { | - type parameter from outer item LL | fn bfnr<U, V: Baz<U>, W: Fn()>(y: T) { | ---- ^ use of generic parameter from outer item | | | generic parameter used in this inner function | help: try introducing a local generic parameter here | LL | fn bfnr<T, U, V: Baz<U>, W: Fn()>(y: T) { | ++ ``` In E0401 generated in hir_typeck: ``` error[E0401]: can't reference `Self` constructor from outer item --> $DIR/do-not-ice-on-note_and_explain.rs:6:13 | LL | impl<B> A<B> { | ------------ the inner item doesn't inherit generics from this impl, so `Self` is invalid to reference LL | fn d() { LL | fn d() { | - `Self` used in this inner item LL | Self(1) | ^^^^ help: replace `Self` with the actual type: `A` ```
Tweak E0401 More accurate span pointing at use place of outer param (at ident instead of full path). Add note explaining why outer item params can't be used in inner item. Use structured suggestion for what `Self` should have been. Follow up to rust-lang#148370. Fix rust-lang#37892.
Tweak E0401 More accurate span pointing at use place of outer param (at ident instead of full path). Add note explaining why outer item params can't be used in inner item. Use structured suggestion for what `Self` should have been. Follow up to rust-lang#148370. Fix rust-lang#37892.
Rollup merge of #148447 - estebank:outer-param-2, r=jackh726 Tweak E0401 More accurate span pointing at use place of outer param (at ident instead of full path). Add note explaining why outer item params can't be used in inner item. Use structured suggestion for what `Self` should have been. Follow up to #148370. Fix #37892.
Rollup of 5 pull requests Successful merges: - rust-lang/rust#144194 (Provide additional context to errors involving const traits) - rust-lang/rust#148232 (ci: add runners for vanilla LLVM 21) - rust-lang/rust#148240 (rustc_codegen: fix musttail returns for cast/indirect ABIs) - rust-lang/rust#148247 (Remove a special case and move another one out of reachable_non_generics) - rust-lang/rust#148370 (Point at inner item when it uses generic type param from outer item or `Self`) r? `@ghost` `@rustbot` modify labels: rollup
Partially address #37892.
In E0401 generated in resolve:
In E0401 generated in hir_typeck: